/**
 * Copyright 2011 Brigham Young University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package edu.byu.nlp.data;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

/**
 * @author rah67
 *
 */
public class Datasets {

	private Datasets() {}
	
	private static class ListDataset<I extends Instance, N extends DatasetInfo> implements Dataset<I, N> {

		private final List<I> data;
		private final N info;
		
		public ListDataset(List<I> data, N info) {
			this.data = data;
			this.info = info;
		}

		/** {@inheritDoc} */
		@Override
		public void shuffle(Random rnd) {
			Collections.shuffle(data);
		}

		/** {@inheritDoc} */
		@Override
		public Iterator<I> iterator() {
			return data.iterator();
		}

		/** {@inheritDoc} */
		@Override
		public N getInfo() {
			return info;
		}
	}
	
	private static class LabeledListDataset extends ListDataset<LabeledInstance, LabeledDatasetInfo>
			implements LabeledDataset {
		public LabeledListDataset(List<LabeledInstance> data, LabeledDatasetInfo info) {
			super(data, info);
		}
	}
	
	public static LabeledDataset newLabeledDataset(List<LabeledInstance> data, LabeledDatasetInfo info) {
		return new LabeledListDataset(data, info);
	}
}
